%% copy riak-0.14.2 source to learn dynamo implementation and erlang
%% author: lichuang
%% copy source from riak_kv_legacy_vnode.erl

%% riak_kv_legacy_vnode: Message translation for legacy vnode requests
%% @doc  QuickCheck tests for riak_core_vnode code

-module(edynamo_kv_legacy_vnode).
-export([rewrite_cast/1,
         rewrite_call/2]).
-include_lib("riak_kv_vnode.hrl").

%% @private
rewrite_cast({vnode_put, {Partition, _Node},
              {FSM_pid, BKey, RObj, ReqID, FSMTime, Options}}) ->
  Req = edynamo_vnode_master:make_request(
          ?KV_PUT_REQ{
            bkey = BKey,
            object = RObj,
            req_id = ReqID,
            start_time = FSMTime,
            options = Options},
          {fsm, undefined, FSM_pid},
          Partition),
  {ok, Req};
rewrite_cast({vnode_get, {Partition,_Node},
    {FSM_pid,BKey,ReqId}}) ->
  Req = edynamo_vnode_master:make_request(
    ?KV_GET_REQ{
      bkey = BKey,
      req_id = ReqId
    },
    {fsm, undefined, FSM_pid},
    Partition),
  {ok, Req};
%% rewrite_cast({vnode_merkle, {RemoteVN,Partition,Merkle,ObjList}}, State) ->
%%     Pid = get_vnode(Partition, State),
%%     gen_fsm:send_event(Pid, {vnode_merkle, {RemoteVN,Merkle,ObjList}}),
%%     {noreply, State};
rewrite_cast({vnode_list_bucket, {Partition,_Node},
    {FSM_pid, Bucket, ReqID}}) ->
  Req = edynamo_vnode_master:make_request(
    #riak_kv_listkeys_req_v1{
      bucket=Bucket,
      req_id=ReqID},
    {fsm, undefined, FSM_pid},
    Partition),
  {ok, Req}.

%% @private
rewrite_call({vnode_del, {Partition,_Node},
    {BKey,ReqID}}, _From) ->
  Req = edynamo_vnode_master:make_request(
    ?KV_DELETE_REQ{bkey=BKey,
      req_id=ReqID},
    noreply,
    Partition),
  {ok, Req}.
